﻿using System.Linq;
using ECommon.Components;
using Infrastructure;
using QueryServices.DTOs;

namespace QueryServices.Ef
{
    [Component]
    public class AccountQueryService :BaseQueryService, 
        IAccountQueryService
    {
        public AccountInfo Find(string name)
        {
            using (Repository.EntityFramework.Accounts.DataContext db = new Repository.EntityFramework.Accounts.DataContext())
            {
                var m = db.AccountInfo.AsNoTracking().Where(x => x.Name == name).Select(x => new AccountInfo
                {
                    Id = x.Id,
                    Password = x.Password,
                    Name = x.Name
                }).SingleOrDefault();
                return m;
            }
        }
    }
}
